﻿
namespace Ocelot.Admin.Api.Application
{
    /// <summary>
    /// 系统服务接口
    /// </summary>
    public class ProjectApiController : IDynamicApiController
    {
        private readonly IProjectService _projectService;
        public ProjectApiController(IProjectService projectService)
        {
            _projectService = projectService;
        }

        #region 查询

        /// <summary>
        /// 分页查询项目信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<SqlSugarPagedList<Project>> GetPageProjectAsync([FromQuery] PageProjectRequest request)
        {
            return await _projectService.GetPageProjectAsync(request);
        }

        #endregion

        #region 新增

        /// <summary>
        /// 新增项目信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<string> InsertProjectAsync(InsertProjectRequest request)
        {
            return await _projectService.InsertProjectAsync(request);
        }

        #endregion

        #region 编辑

        /// <summary>
        /// 更新项目信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<string> UpdateProjectAsync(UpdateProjectRequest request)
        {
            return await _projectService.UpdateProjectAsync(request);
        }

        /// <summary>
        /// 启用或禁用项目信息
        /// </summary>
        /// <param name="projectId">项目Id</param>
        /// <param name="enabled">是否有效</param>
        /// <returns></returns>
        public async Task<string> PatchProjectAsync(int projectId, bool enabled)
        {
            return await _projectService.PatchProjectAsync(projectId, enabled);
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除项目信息
        /// </summary>
        /// <param name="projectId">项目Id</param>
        /// <returns></returns>
        public async Task<string> DeleteProjectAsync(int projectId)
        {
            return await _projectService.DeleteProjectAsync(projectId);
        }

        #endregion
    }
}